const { ccclass, property } = cc._decorator;
import GameDataMgr from "./GameDataMgr";
import EventMgr from "./EventMgr";
import SdkHelper from "./SdkHelper";
import EngineUtil from "./EngineUtil";
import PlayerDataSys from "./PlayerDataSys";
import frameworkManager from "./frameworkManager";

@ccclass
export default class MineCtrl extends cc.Component {
    @property(cc.Node)
    btn_switch_on = null;
    @property(cc.Node)
    btn_switch_off = null;
    @property(cc.Node)
    aboutNode = null;
    @property(cc.Node)
    webNode = null;

    onLoad() {
        if (!EngineUtil.localStorageGetItem("xiaomi_default_set", "")) {
            EngineUtil.localStorageSetItem("xiaomi_reco_switch", "1");
            EngineUtil.localStorageSetItem("xiaomi_default_set", "1");
        }
        this.setRecon();
    }

    start() {}

    userCallback() {
        this.webNode.active = true;
        EventMgr.trigger(SHOW_XIAOMI_PRI, GameDataMgr.WebUrlType.USER_TYPE);
    }

    priCallback() {
        this.webNode.active = true;
        EventMgr.trigger(SHOW_XIAOMI_PRI, GameDataMgr.WebUrlType.PRIVACY_TYPE);
    }

    aboutCallback() {
        this.aboutNode.active = true;
        EventMgr.trigger(SHOW_XIAOMI_SURFACE_ABOUT);
    }

    feedback() {
        frameworkManager.log("客服");
        var head = PlayerDataSys.wx_head,
            name = PlayerDataSys.user_name,
            gender = PlayerDataSys.wx_gender;
        PlayerDataSys.user_id;
        SdkHelper.reportData("u_click_kefu");
        SdkHelper.feedback(name, head, gender);
    }

    reconTouch() {
        var reco_switch = EngineUtil.localStorageGetItem("xiaomi_reco_switch", "");
        if (reco_switch === "1") {
            EngineUtil.localStorageSetItem("xiaomi_reco_switch", "");
        } else {
            EngineUtil.localStorageSetItem("xiaomi_reco_switch", "1");
        }
        this.setRecon();
    }

    setRecon() {
        var reco_switch = EngineUtil.localStorageGetItem("xiaomi_reco_switch", "");
        this.btn_switch_on.active = reco_switch === "1";
        this.btn_switch_off.active = reco_switch !== "1";
    }
}
